<html>
<head>
<script>
	var tabMap = {};	// maps the tab to the sudoku definition.
	chrome.extension.onConnect.addListener(function(port) {
		var tab = port.sender.tab;

		// This will get called from the content script using PostMessage.
		// |feedUrls| is a list of URL feeds found on the page. We only need 1 to
		// enable the PageAction icon in the Omnibox.
		port.onMessage.addListener(function(param) {
			if (param) {
				tabMap[tab.id] = param;
			}
			chrome.pageAction.setTitle({ tabId: tab.id,
					     title: "Click to play..." });
			chrome.pageAction.show(tab.id);
		});
	});

	// Chrome will call into us when the user clicks on the icon in the OmniBox.
	chrome.pageAction.onClicked.addListener(function(tab) {
		var data = tabMap[tab.id];
		if (data) {
			var url = chrome.extension.getURL("grid.html") + "?p=" + data;
			chrome.tabs.create({url: url, windowId: window.id});
		}
	});

	chrome.tabs.onRemoved.addListener(function(reply) {
		tabMap[reply.tabId] = null;
	});
</script>
</head>
</html>

